package p270jp.pxv.android.activity;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;
import androidx.appcompat.app.AlertController;
import androidx.appcompat.app.AlertDialog;
import com.amazon.device.ads.DTBAdMRAIDBannerController;
import com.google.firebase.remoteconfig.internal.ConfigFetchHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.greenrobot.eventbus.EventBusException;
import p013ad.Action;
import p014ae.C0100j9;
import p014ae.C0124n;
import p014ae.DialogInterface$OnClickListenerC0079g;
import p014ae.DialogInterface$OnClickListenerC0088h;
import p014ae.RunnableC0091i;
import p015af.BrowsingHistoryProperties;
import p090d0.C2518n;
import p116e.ActivityC2727f;
import p134ei.AnalyticsAction;
import p134ei.PixivAnalytics;
import p160fj.RemoteConfigFetchService;
import p165fo.C3114c;
import p165fo.Subscribe;
import p187gl.PixivAppApiRequest;
import p210hh.PixivAccountManager;
import p248j2.C3896b;
import p270jp.pxv.android.R;
import p270jp.pxv.android.event.DownloadWorkEvent;
import p270jp.pxv.android.event.ShowLiveMenuOnLongClickEvent;
import p270jp.pxv.android.event.ShowWorkMenuOnLongClickEvent;
import p270jp.pxv.android.legacy.event.ShowMuteSettingEvent;
import p270jp.pxv.android.legacy.model.BrowsingHistory;
import p270jp.pxv.android.legacy.model.PixivTag;
import p270jp.pxv.android.legacy.model.PixivUser;
import p274k2.ContextCompat;
import p325m0.MutabilityOwnership;
import p347mm.BrowsingHistoryManager;
import p468re.LogoutService;
import p484s6.C5998s;
import p569vd.C6832d;
import p603wm.AbstractC6949c;
import p639y6.C7296l;
import p639y6.C7298n;
import p639y6.C7300p;
import p665z6.C7465t;
import p671zc.CompositeDisposable;

/* renamed from: jp.pxv.android.activity.a */
/* loaded from: classes2.dex */
public abstract class BaseActivity extends ActivityC2727f {

    /* renamed from: E */
    public static final /* synthetic */ int f18756E = 0;

    /* renamed from: A */
    public PixivAnalytics f18757A;

    /* renamed from: B */
    public BrowsingHistoryManager f18758B;

    /* renamed from: C */
    public AbstractC6949c<LogoutService> f18759C;

    /* renamed from: D */
    public AbstractC6949c<CompositeDisposable> f18760D;

    /* renamed from: s */
    public boolean f18761s;

    /* renamed from: t */
    public AbstractC4150e f18762t;

    /* renamed from: u */
    public AbstractC4149d f18763u;

    /* renamed from: v */
    public BroadcastReceiver f18764v;

    /* renamed from: w */
    public BroadcastReceiver f18765w;

    /* renamed from: x */
    public IntentFilter f18766x;

    /* renamed from: y */
    public IntentFilter f18767y;

    /* renamed from: z */
    public RemoteConfigFetchService f18768z;

    /* compiled from: BaseActivity.java */
    /* renamed from: jp.pxv.android.activity.a$a */
    /* loaded from: classes2.dex */
    public class C4146a extends BroadcastReceiver {
        public C4146a() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            BaseActivity.this.finish();
        }
    }

    /* compiled from: BaseActivity.java */
    /* renamed from: jp.pxv.android.activity.a$b */
    /* loaded from: classes2.dex */
    public class C4147b extends BroadcastReceiver {
        public C4147b() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            BaseActivity.this.f18761s = true;
        }
    }

    /* compiled from: BaseActivity.java */
    /* renamed from: jp.pxv.android.activity.a$c */
    /* loaded from: classes2.dex */
    public class C4148c implements AbstractC4149d {
        public C4148c() {
        }
    }

    /* compiled from: BaseActivity.java */
    /* renamed from: jp.pxv.android.activity.a$d */
    /* loaded from: classes2.dex */
    public interface AbstractC4149d {
    }

    /* compiled from: BaseActivity.java */
    /* renamed from: jp.pxv.android.activity.a$e */
    /* loaded from: classes2.dex */
    public interface AbstractC4150e {
        /* renamed from: b */
        void mo408b();
    }

    public BaseActivity() {
    }

    @Deprecated
    /* renamed from: S0 */
    public void m4679S0(String str, AbstractC4150e eVar) {
        m4678T0(new String[]{str}, eVar);
    }

    @Deprecated
    /* renamed from: T0 */
    public void m4678T0(String[] strArr, AbstractC4150e eVar) {
        C4148c cVar = new C4148c();
        ArrayList arrayList = new ArrayList();
        boolean z = false;
        for (String str : strArr) {
            if (ContextCompat.m4266a(this, str) != 0) {
                arrayList.add(str);
            }
        }
        if (arrayList.size() == 0) {
            z = true;
        } else {
            C3896b.m5007b(this, (String[]) arrayList.toArray(new String[arrayList.size()]), DTBAdMRAIDBannerController.ANIMATION_DURATION);
        }
        if (z) {
            eVar.mo408b();
            return;
        }
        this.f18762t = eVar;
        this.f18763u = cVar;
    }

    /* renamed from: U0 */
    public void m4677U0(Intent intent) {
        Intent intent2 = new Intent();
        intent2.setAction("jp.pxv.android.CLEAR_STACK");
        intent2.setPackage(getPackageName());
        sendBroadcast(intent2);
        super.startActivity(intent);
    }

    @Override // p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity, android.content.ComponentCallbacks
    public void onConfigurationChanged(Configuration configuration) {
        configuration.toString();
        super.onConfigurationChanged(configuration);
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f18764v = new C4146a();
        this.f18765w = new C4147b();
        this.f18757A = (PixivAnalytics) C2518n.m7641d(PixivAnalytics.class);
        this.f18758B = (BrowsingHistoryManager) C2518n.m7641d(BrowsingHistoryManager.class);
        this.f18759C = C2518n.m7638h(LogoutService.class);
        this.f18760D = C2518n.m7638h(CompositeDisposable.class);
        this.f18766x = new IntentFilter();
        this.f18767y = new IntentFilter();
        this.f18768z = (RemoteConfigFetchService) C2518n.m7641d(RemoteConfigFetchService.class);
        this.f18766x.addAction("jp.pxv.android.CLEAR_STACK");
        this.f18767y.addAction("jp.pxv.android.MUTE");
        registerReceiver(this.f18764v, this.f18766x);
        registerReceiver(this.f18765w, this.f18767y);
    }

    @Override // p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        unregisterReceiver(this.f18764v);
        unregisterReceiver(this.f18765w);
        this.f18760D.getValue().m80f();
        super.onDestroy();
    }

    @Subscribe
    public void onEvent(ShowMuteSettingEvent showMuteSettingEvent) {
        ArrayList<PixivUser> candidateUsers = showMuteSettingEvent.getCandidateUsers();
        ArrayList<PixivTag> candidateTags = showMuteSettingEvent.getCandidateTags();
        MutabilityOwnership.m3745m(candidateUsers, "muteCandidateUsers");
        MutabilityOwnership.m3745m(candidateTags, "muteCandidateTags");
        Intent intent = new Intent(this, MuteSettingActivity.class);
        intent.putExtra("CANDIDATE_USERS", candidateUsers);
        intent.putExtra("CANDIDATE_TAGS", candidateTags);
        startActivity(intent);
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onPause() {
        boolean containsKey;
        super.onPause();
        C3114c b = C3114c.m6284b();
        synchronized (b) {
            containsKey = b.f14671b.containsKey(this);
        }
        if (containsKey) {
            C3114c.m6284b().m6274l(this);
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    @SuppressLint({"MissingSuperCall"})
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i == 500) {
            if (iArr.length <= 0 || iArr[0] != 0) {
                Toast.makeText(BaseActivity.this, (int) R.string.permission_needed_error, 1).show();
            } else {
                this.f18762t.mo408b();
            }
            this.f18762t = null;
            this.f18763u = null;
        }
    }

    @Override // androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onResume() {
        super.onResume();
        try {
            C3114c.m6284b().m6276j(this);
        } catch (EventBusException unused) {
        }
        BrowsingHistoryManager eVar = this.f18758B;
        if (eVar.f23045b.f16506l) {
            if (eVar.f23044a.f727a.getLong("browsing_history_illusts_last_sync_time_millis", 0) + 180000 < System.currentTimeMillis()) {
                List<BrowsingHistory> findIllusts = eVar.f23047d.findIllusts(100);
                if (!findIllusts.isEmpty()) {
                    PixivAppApiRequest aVar = eVar.f23046c;
                    ArrayList<Long> a = eVar.m3546a(findIllusts);
                    Objects.requireNonNull(aVar);
                    aVar.f15667a.m5513c().m969g(new C7298n(aVar, a, 9)).m1010g(new Action(findIllusts) { // from class: mm.d

                        /* renamed from: b */
                        public final /* synthetic */ List f23043b;

                        {
                            this.f23043b = r2;
                        }

                        @Override // p013ad.Action
                        public final void run() {
                            BrowsingHistoryManager eVar2 = BrowsingHistoryManager.this;
                            eVar2.f23047d.deleteByBrowsingHistories(this.f23043b);
                        }
                    }, C6832d.f29070l);
                }
                BrowsingHistoryProperties aVar2 = eVar.f23044a;
                aVar2.f727a.edit().putLong("browsing_history_illusts_last_sync_time_millis", System.currentTimeMillis()).apply();
            }
            if (eVar.f23044a.f727a.getLong("browsing_history_novels_last_sync_time_millis", 0) + 180000 < System.currentTimeMillis()) {
                List<BrowsingHistory> findNovels = eVar.f23047d.findNovels(100);
                if (!findNovels.isEmpty()) {
                    PixivAppApiRequest aVar3 = eVar.f23046c;
                    ArrayList<Long> a2 = eVar.m3546a(findNovels);
                    Objects.requireNonNull(aVar3);
                    aVar3.f15667a.m5513c().m969g(new C7300p(aVar3, a2, 6)).m1010g(new C0124n(eVar, findNovels, 2), C0100j9.f423f);
                }
                BrowsingHistoryProperties aVar4 = eVar.f23044a;
                aVar4.f727a.edit().putLong("browsing_history_novels_last_sync_time_millis", System.currentTimeMillis()).apply();
            }
        }
        if (this.f18761s) {
            this.f18761s = false;
            new Handler().post(RunnableC0091i.f391a);
        }
        RemoteConfigFetchService aVar5 = this.f18768z;
        ConfigFetchHandler aVar6 = aVar5.f14645a.f21056g;
        aVar6.f10067f.m3618b().continueWithTask(aVar6.f10064c, new C7465t(aVar6, 3600, 1)).onSuccessTask(C5998s.f26024i).addOnCompleteListener(new C7296l(aVar5, 23));
    }

    public BaseActivity(int i) {
        super(i);
    }

    @Subscribe
    public void onEvent(DownloadWorkEvent downloadWorkEvent) {
        m4679S0("android.permission.WRITE_EXTERNAL_STORAGE", new C7298n(this, downloadWorkEvent, 3));
    }

    @Subscribe
    public void onEvent(ShowLiveMenuOnLongClickEvent showLiveMenuOnLongClickEvent) {
        this.f18757A.m6528b(16, AnalyticsAction.MENU_SHOW_VIA_LONG_PRESS);
        AlertDialog.C0305a aVar = new AlertDialog.C0305a(this);
        String[] strArr = PixivAccountManager.m5511e().f16499e == showLiveMenuOnLongClickEvent.getLive().owner.user.f19078id ? new String[]{getString(R.string.share)} : new String[]{getString(R.string.share), getString(R.string.mute_settings)};
        DialogInterface$OnClickListenerC0088h hVar = new DialogInterface$OnClickListenerC0088h(this, showLiveMenuOnLongClickEvent, 0);
        AlertController.C0299b bVar = aVar.f1085a;
        bVar.f1066p = strArr;
        bVar.f1068r = hVar;
        aVar.m12013a().show();
    }

    @Subscribe
    public void onEvent(ShowWorkMenuOnLongClickEvent showWorkMenuOnLongClickEvent) {
        String[] strArr;
        if (showWorkMenuOnLongClickEvent.getWork().visible) {
            this.f18757A.m6528b(16, AnalyticsAction.MENU_SHOW_VIA_LONG_PRESS);
            AlertDialog.C0305a aVar = new AlertDialog.C0305a(this);
            if (showWorkMenuOnLongClickEvent.getFromNovelSeries()) {
                strArr = PixivAccountManager.m5511e().f16499e == showWorkMenuOnLongClickEvent.getWork().user.f19078id ? new String[]{getString(R.string.share)} : new String[]{getString(R.string.share), getString(R.string.mute_settings)};
            } else {
                strArr = PixivAccountManager.m5511e().f16499e == showWorkMenuOnLongClickEvent.getWork().user.f19078id ? new String[]{getString(R.string.share), getString(R.string.illust_save)} : new String[]{getString(R.string.share), getString(R.string.illust_save), getString(R.string.mute_settings)};
            }
            DialogInterface$OnClickListenerC0079g gVar = new DialogInterface$OnClickListenerC0079g(this, showWorkMenuOnLongClickEvent, 0);
            AlertController.C0299b bVar = aVar.f1085a;
            bVar.f1066p = strArr;
            bVar.f1068r = gVar;
            aVar.m12013a().show();
        }
    }
}
